/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tetris.model;

import java.awt.Color;
import java.awt.Graphics;
import java.lang.Exception;
import java.util.Random;

public class CellModel extends Model{
    private Boolean occupied;
    private Color color;

    private int linenumber;
    private int cellnumber;

    public CellModel(){
        this.occupied = false;
        this.color = Color.BLACK;
    }

    public void occupied() throws Exception{
        if(this.occupied){
            throw new Exception();
        }
    }

    public boolean isOccupied(){
        return this.occupied;
    }

    public void occupy(Color color){
        this.occupied = true;
        this.color = color;
    }

    public Color getColor(){
        return this.color;
    }

    public void setColor(Color c){
        this.color = c;
    }

    public void unoccupy(){
        this.occupied = false;
        this.color = Color.BLACK;
    }

    public void paintCell(int y, int x, Graphics g){
        g.setColor(this.color);
        g.drawRect(x*20, y*20, 20, 20);
        g.fillRect(x*20, y*20, 19, 19);
    }

    private Color getRandomColor(){
        Random r = new Random();
        Color ret = Color.BLUE;
        int rand = r.nextInt(4);
        System.out.println("Random number is: " + rand);
        switch (rand){
            case 0:
                ret = Color.BLUE; break;
            case 1:
                ret = Color.RED; break;
            case 2:
                ret = Color.YELLOW;
                break;
            case 3: 
                ret = Color.ORANGE;
                break;
            case 4: 
                ret = Color.GREEN;
                break;
        }
        return ret;
    }
}
